package cn.com.yusys.yusp.admin.web.rest;

import cn.com.yusys.yusp.admin.domain.CustBasicInfo;
import cn.com.yusys.yusp.admin.service.SystemUtilService;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.web.rest.CommonResource;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/org")
public class AcrmCustOrgResource extends CommonResource<CustBasicInfo, String> {

    @Autowired
    private SystemUtilService service;

    /**
     *
     * @方法名称: getcustById
     * @方法描述: 依据编号查询名称（前端组件用）
     * @参数与返回说明:
     * @算法描述:
     */
    @GetMapping("/getcustById")
    public ResultDto<List<Map<String, Object>>> getcustById(String loginCode) {
        List<Map<String, Object>> cust = new ArrayList<>();
        if (StringUtils.isNotBlank(loginCode)){
            List<String> mgrList = Arrays.asList(loginCode.split(","));
            cust = service.getcustById(mgrList);
        }
        return new ResultDto<>(cust);
    }

    @GetMapping("/getcustmgr")
    public ResultDto<List<Map<String, Object>>> getcustmgr(QueryModel queryModel) {
        String orgId = "";
        if(queryModel.getCondition().containsKey("orgCode")){
            orgId = queryModel.getCondition().get("orgCode").toString();
        }
        queryModel.getCondition().put("orgId",orgId);
        List<Map<String, Object>> list = service.getCustMgrByOrgName(queryModel);
        return new ResultDto<>(list);
    }
    @Override
    protected CommonService getCommonService() {
        return null;
    }
}
